package com.yoso.base.interfaces.controller;

import com.yoso.base.entity.BaseEntity;
import com.yoso.base.infrastructure.factory.BeanFactory;
import com.yoso.base.interfaces.vo.BaseVo;
import com.yoso.base.service.BaseEntityExample;
import com.yoso.base.service.IBaseService;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yoso
 */
public abstract class AbstractBaseController<V extends BaseVo, E extends BaseEntity> extends AbstractController {

    public abstract E V2E(V data);

    public abstract V E2V(E data);

    public List<E> bachV2E(Iterable<V> vs) {
        List<E> result = new ArrayList<>();
        vs.forEach(e -> result.add(V2E(e)));
        return result;
    }

    public List<V> bachE2V(Iterable<E> es) {
        List<V> result = new ArrayList<>();
        es.forEach(e -> result.add(E2V(e)));
        return result;
    }

    public <T> T convert(Object source, Class<T> target) {
        return BeanFactory.convertBean(source, target);
    }

    public abstract IBaseService<V, ? extends BaseEntityExample> getService();
}
